from django.http import JsonResponse


class ResponseStatus:
    OUTTIME_CODE = {
        "code": 401,
        "message": "token outtime",
        "data": None
    }

    def __init__(self):
        self.SUCCESS_CODE = {
            "code": 200,
            "message": "success",
            "data": None
        }
        self.FALSE_CODE = {
            "code": 500,
            "message": "false",
            "data": None
        }
        self.OPTION_FAILED_CODE = {
            "code": 501,
            "message": "option failed",
            "data": None
        }
        self.UNLOGIN_CODE = {
            "code": 401,
            "message": "用户未登录",
            "data": None
        }

    def success(self, data=None, message="success"):
        """
        成功
        """
        result = self.SUCCESS_CODE
        result["message"] = message
        result["data"] = data
        return JsonResponse(result)

    def unlogin(self, data=None, message="unlogin"):
        """
        未登录
        """
        result = self.UNLOGIN_CODE
        result["message"] = message
        result["data"] = data
        return JsonResponse(result)

    def failed(self, data=None, message="failed"):
        """
        失败
        """
        result = self.FALSE_CODE
        result["message"] = message
        result["data"] = data
        return JsonResponse(result)

    def token_outtime(self, data=None, message="token outtime"):
        """
        token过期
        """
        result = self.OUTTIME_CODE
        result["message"] = message
        result["data"] = data
        return JsonResponse(result)
